<template>
	<view>
		<view>
			<u-steps :current="stepNum">
				<u-steps-item title="手机号"></u-steps-item>
				<u-steps-item title="基本信息"></u-steps-item>
				<u-steps-item title="登录账号"></u-steps-item>
			</u-steps>
		</view>

		<view v-show="stepNum === 0">
			<button type="primary" open-type="getPhoneNumber" @getphonenumber="getUserPhoneNumber">点击授权手机号</button>
		</view>

		<view v-show="stepNum === 1">
			<button type="primary" open-type="getUserInfo" @getuserinfo="getuserinfo">获取用户信息</button>
		</view>

		<view v-show="stepNum === 2">
			<view style="height: 600rpx;width: 100%">
				<u-form :model="form" ref="form1" label-width="150rpx">
					<u-form-item label="昵称" prop="nickName"><u-input v-model="form.nickName" /></u-form-item>
					<u-form-item label="手机号" prop="phoneNumber"><u-input v-model="form.phoneNumber" /></u-form-item>
					<u-form-item label="登录密码" prop="password"><u-input v-model="form.password" /></u-form-item>
					<u-form-item label="部门" prop="deptId">
						<ld-cascader v-model="deptDefault.value" :list="deptDefault.options" @change="deptChange" clearable></ld-cascader>
					</u-form-item>

				</u-form>
				
			</view>
		</view>
		
		

	</view>
</template>

<script>
	import {
		wechatGetMobile,
		wechatDeptTree
	} from '@/api/api-weixin'
	export default {
		data() {
			return {
				stepNum: 0,
				form: {
					username: '',
					nickName: '',
					password: '',
					phoneNumber: '',
					deptLabel: ''
				},
				deptDefault: {
					value: [],
					options: []
				}
			}
		},
		onLoad(option) {
			this.openid = option.openId
			let that = this
			wechatDeptTree(this.openid).then(({ data }) => {
			  console.log('部门树列表', data)
			  that.deptDefault.options = data[0].children
			})
		},
		methods: {
			getUserPhoneNumber(e) {
				const that = this
				wechatGetMobile(e.detail.code).then(({
					data
				}) => {
					that.form.phoneNumber = data.phoneNumber
					that.form.password = data.phoneNumber.substring(data.phoneNumber.length - 4)
					that.stepNum = 1


				})
			},
			getuserinfo(e) {
				console.log(e)
				let that = this
				uni.getUserInfo({
					provider: 'weixin',
					lang: 'zh_CN',
					success: ({
						userInfo
					}) => {
						console.log('用户信息', userInfo)
						that.form.nickName = userInfo.nickName
						that.form.sex = userInfo.gender
						that.stepNum = 2
					}
				})
			},
			deptChange(ss) {
				console.log(ss)
			}
		}
	}
</script>

<style>
</style>